#pragma once

#include <logger/memorystream.hpp>
#include <QtCore/QAbstractItemModel.h>




class LoggerModel
	: public QAbstractTableModel
{
	Q_OBJECT

private:

	logger::memorystream::ptr   m_stream;
	QList<logger::entry>        m_entries;
	QTimer                      m_timer;

public:

	LoggerModel(QObject* parent, services::provider::const_ptr provider);
	virtual ~LoggerModel();



	/**
	 * Returns the number of rows under the given parent.
	 */
	virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;

	/**
	 * Returns the number of columns for the children of the given parent.
	 */
	virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;

	/**
	 * Returns the data for the given role and section in the header with the specified orientation.
	 */
	virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;

	/**
	 * Returns the data stored under the given role for the item referred to by the index.
	 */
	virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;

public slots:

	/**
	 * Fetches all entries from the stream and
	 * updates the model, if necessary.
	 */
	void update();
};
///////////////////////////////////////////////////////////////////////////////////////////////////
